Skip to content

Conversation

martincostello
Copy link
Member

Contributes to #97.

Changes

Address some native AoT warnings with .NET 8.

The only remaining warning is from the usage of ReflectionHelper.CallStaticMethod().

Need to update the documentation to state somewhere that SQL instrumentation is not enabled when using native AoT.

Merge requirement checklist

  • Unit tests added/updated
  • CHANGELOG.md file updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Address some native AoT warnings with .NET 8.

The only remaining warning is from the usage of `ReflectionHelper.CallStaticMethod()`.
@martincostello martincostello added the enhancement New feature or request label Jul 15, 2025
@martincostello martincostello marked this pull request as ready for review July 15, 2025 14:16
@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 14:16
@martincostello martincostello requested a review from a team as a code owner July 15, 2025 14:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses native AoT warnings in .NET 8 by implementing conditional compilation directives and runtime checks to handle features that are incompatible with native AoT compilation, particularly SQL instrumentation.

  • Adds RequiresUnreferencedCode attribute to SqlClientInitializer to warn about trimming incompatibility
  • Refactors the static initializer array to use runtime checks for native AoT compatibility
  • Optimizes various code patterns to use .NET-specific features where available

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Grafana.OpenTelemetry.Base/Instrumentations/SqlClientInitializer.cs Adds RequiresUnreferencedCode attribute to indicate trimming incompatibility
src/Grafana.OpenTelemetry.Base/Instrumentations/InstrumentationInitializer.cs Refactors static array to dynamic method with runtime checks for SqlClient compatibility
src/Grafana.OpenTelemetry.Base/GrafanaOpenTelemetrySettings.cs Updates collection initialization and optimizes array allocation patterns
src/Grafana.OpenTelemetry.Base/GrafanaOpenTelemetryEventSource.cs Adds source generator support for JSON serialization in .NET

@martincostello martincostello merged commit 6edb749 into main Jul 16, 2025
13 checks passed
@martincostello martincostello deleted the fix-some-aot-warnings branch July 16, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants